/*
 *  $Id$

    Copyright (C) 2008  Nathaniel Waisbrot

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package termint.game.dungeon;

import termint.game.NHObject;

/**
 * @author Nathaniel Waisbrot
 *
 */
public abstract class Room extends NHObject {
	private Integer t,l,b,r;
	public boolean locationKnown() {
		return !(t==null && l==null && b==null && r==null);
	}
	
	private Room strApp(StringBuilder sb, Object o) {
		if (o != null)
			sb.append(o);
		else
			sb.append('?');
		return this;
	}
	
	public String toString() {
		StringBuilder sb = new StringBuilder(getClass().getSimpleName());
		if (locationKnown()) {
			sb.append('@');
			strApp(sb, t).strApp(sb, l).strApp(sb, b).strApp(sb,r);
		}
		return sb.toString();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (getClass().isInstance(obj)) {
			Room robj = (Room)obj;
			return (!locationKnown() && !robj.locationKnown()) || 
					(t.equals(robj.t) && l.equals(robj.l) && b.equals(robj.b) && r.equals(robj.r));
		} else {
			return false;
		}
	}	
}
